package com.test;


import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;

/**
 * <dl>
 * <dt>Send</dt>
 * <dd>Description:生产者属性配置从配置文件中获取</dd>
 * <dd>Copyright: Copyright (C) 2006</dd>
 * <dd>CreateDate: 2019-3-7</dd>
 * </dl>
 *
 * @author Administrator
 */
public class Send2 {
    public static void main(String[] args) {
        //与kafka连接，参考官网：http://kafka.apache.org/documentation/#producerapi
        Properties props = PropertiesUtil.getProperties("producer");
        Producer<String, String> producer = new KafkaProducer<String, String>(props);
        int max = 100;
        for(int i = 0; i < max; i++){
            producer.send(new ProducerRecord<String, String>("test", Integer.toString(i), Integer.toString(i)));
        }
        //关闭
        producer.close();
    }
}
